﻿using System.Data;
using WorkFlow.DBProxy;
using WorkFlow.Engine;
using WorkFlow.Engine.NSActivity;

namespace WorkFlow.web.PublicCode
{
    public class GetSpecifyCase
    {
        public DataTable GetCase(string actStr, int userID)
        {
            int actID = -1;
            if (!int.TryParse(actStr.Trim(), out actID)) return null;

            WfActivity act = WfActivityController.CreateActivityController().GetActivity(actID, userID);
            if (act == null) return null;

            switch (act.Status)
            {
                case WfFieldCode.DbReadyState:
                    act.Run();
                    break;

                case WfFieldCode.DbSuspendState:
                    act.Resume();
                    break;

                case WfFieldCode.DbRollbackState:
                    act.Run();
                    break;

                default:
                    break;
            }
            string sql =
                string.Format(@"select F_ID AS CASEID,F_CONTENT as CONTENT,F_TITLE as TITLE from t_cases where f_id =(
                                                select f_case_id from t_processes where f_id={0}
                                            )", act.ProcessId);
            return DB.MapToDataTable(sql);
        }
    }
}